﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLTV_V2.DataAccess;

namespace QLTV_V2
{
    public partial class frmGetTacGia : Form
    {
        public frmGetTacGia()
        {
            InitializeComponent();
        }
        Utilities uti = new Utilities();
        ConnectData conn = new ConnectData();
        private void frmGetTacGia_Load(object sender, EventArgs e)
        {
            dgv_TacGia.DataSource = uti.getDataSource("TacGia", "MaTacGia");
            comb_Cot.Items.Add("Ký hiệu");
            comb_Cot.Items.Add("Tên tác giả");
            comb_Cot.SelectedItem = "Ký hiệu";
        }
        //Khai báo 1 hàm delegate
        public delegate void GetString(string Mystring1, string Mystring2);
        //khai báo 1 kiểm hàm dalegate
        public GetString MyGetData;
        string getSQL()
        {
            string sql = "select * from TacGia ";
            if (comb_Cot.SelectedItem.ToString() =="Ký hiệu")
                sql += "where MaTacGia like N'%" + txt_Values.Text + "%' ";
            if (comb_Cot.SelectedItem.ToString() =="Tên tác giả")
                sql += "where TenTacGia like N'%" + txt_Values.Text + "%'";
            return sql;
            
        }
        private void txt_Values_TextChanged(object sender, EventArgs e)
        {
            dgv_TacGia.DataSource = conn.GetDataTable(getSQL());
        }

        private void dgv_TacGia_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            uti.dgv_GetSTT_RowHeader(sender, e, dgv_TacGia);
        }

        private void dgv_TacGia_DoubleClick(object sender, EventArgs e)
        {
            if (MyGetData != null)
            {
                string maTG, tenTG;
                int dong = dgv_TacGia.CurrentCell.RowIndex;
                maTG = dgv_TacGia.Rows[dong].Cells["MaTacGia"].Value.ToString();
                tenTG = dgv_TacGia.Rows[dong].Cells["TenTacGia"].Value.ToString();
                MyGetData(maTG, tenTG);
            }
            this.Close();
        }

    }
}
